//
//  XSNoDataView.m
//  MovingLoaniOS
//
//  Created by 谷峰 on 2018/9/25.
//  Copyright © 2018 - 2019 GWMFC. All rights reserved.
//

#import "XSNoDataView.h"
#import "Macros.h"
@interface XSNoDataView ()
@property (nonatomic, strong, nullable) ButtonBlock block;
@property (nonatomic, strong, nullable) UIButton *button;
@end


@implementation XSNoDataView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.frame = CGRectMake(Main_Screen_Width/2-Main_Screen_Width/4, 40, Main_Screen_Width / 2, Main_Screen_Width / 2);
        [self addSubview:imageView];

        imageView.image = [UIImage imageNamed:@"requestFail"];
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(0, imageView.frame.origin.y+20+Main_Screen_Width/2, Main_Screen_Width, 30);
        label.textColor = [UIColor lightGrayColor];
        label.text = @"服务出错，请稍后重试";
        label.textAlignment = NSTextAlignmentCenter;
        label.numberOfLines = 0;
        [self addSubview:label];
        UIButton *refreshBTN = [UIButton buttonWithType:UIButtonTypeCustom];        [refreshBTN setTitle:@"重新加载" forState:UIControlStateNormal];
        [refreshBTN setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        refreshBTN.titleLabel.font = [UIFont systemFontOfSize:14];
        refreshBTN.layer.masksToBounds = YES;
        refreshBTN.layer.borderWidth = 1;
        refreshBTN.layer.cornerRadius = 3;
        refreshBTN.layer.borderColor = [UIColor lightGrayColor].CGColor;        refreshBTN.frame = CGRectMake(Main_Screen_Width/2-50, label.frame.origin.y+60, 100, 30);
        [self addSubview:refreshBTN];
        [refreshBTN addTarget:self action:@selector(buttonAction) forControlEvents:(UIControlEventTouchUpInside)];
        
    }
    return self;
    
}
//实现block回调的方法
- (void)addButtonAction:(ButtonBlock)block {
    self.block = block;
    
}
- (void)buttonAction {
    if (self.block) {
        self.block(self);
        
    }
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
